#include <stdio.h>
#include <string.h>

void my_sort(int *p, int len, int flag){
	int temp = 0;
	int i = 0;
	int j = 0;
	if(0 == flag){ // 升序
		for(i = 0; i < len-1; i++){
			for(j = 0; j < len-1-i; j++){
				if(p[j] > p[j+1]){
					temp = p[j];
					p[j] = p[j+1];
					p[j+1] = temp;
				}
			}
		}
	}else if(1 == flag){ // 降序
		for(i = 0; i < len-1; i++){
			for(j = 0; j < len-1-i; j++){
				if(p[j] < p[j+1]){
					temp = p[j];
					p[j] = p[j+1];
					p[j+1] = temp;
				}
			}
		}
	}
	return;
}

// 打印数组元素
void print_arr(const int *p, int len){
	for(int i = 0; i < len; i++){
		printf("%d  ", p[i]);
	}
	printf("\n");
	return;
}

int main(int argc, const char *argv[])
{
	int s[10] = {5, 1, 9, 3, 7, 8, 6, 2, 10, 4};
	// 排序前:
	print_arr(s, 10);

	if(!strcmp(argv[1], "-升序")){
		my_sort(s, 10, 0);
	}else if(!strcmp(argv[1]+1, "降序")){
		my_sort(s, 10, 1);
	}

	// 排序后:
	print_arr(s, 10);

	return 0;
}
